<%= simple_form_for(@invoice) do |f| %>
<%= f.error_notification %>
<%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>

<div class="row">
	<div class="col-md-6">
		<%= f.input :customer_id, collection: Customer.all,label: '客户' %>

	</div>
	<div class="col-md-6">
		<div class="form-group date optional form-group-valid">
			<label class="form-control-label date optional" for="invoice_invoice_date">开票日期</label>
			<div class="input-group">
				<input name="invoice[invoice_date]" class="form-control date-picker" id="invoice_invoice_date" type="text" data-date-format="yyyy-mm-dd">
				<span class="input-group-addon"> <i class="fa fa-calendar"></i> </span>
			</div>
		</div>
	</div>
</div>

<div class="row">
	<div class="col-md-6">
		<%= f.input :invoice_no, label: '发票号码' %>
	</div>
	<div class="col-md-6">
		<%= f.input :invoice_code, label: '发票代码' %>
	</div>
</div>
<div class="row">
	<div class="col-md-6">
		<%= f.input :invoice_index_code, label: '开票编码' %>
	</div>
	<div class="col-md-6">
		<%= f.input :settlement_slip_no, label: '结算单号' %>
	</div>
</div>
<div class="row">
	<div class="col-md-6">
		<%= f.input :amount, label: '金额' %>
	</div>
	<div class="col-md-6">
		<%= f.input :tax_rate, label: '税率' %>
	</div>
</div>

<div class="row">
	<div class="col-md-6">
		<%= f.input :first_installment_amount, label: '首款预收金额' %>
	</div>
	<div class="col-md-6">

		<div class="form-group date optional form-group-valid">
			<label class="form-control-label date optional" for="invoice_first_installment_date">首款预收日期</label>
			<div class="input-group">
				<input name="invoice[first_installment_date]" class="form-control date-picker" id="invoice_first_installment_date" type="text" data-date-format="yyyy-mm-dd">
				<span class="input-group-addon"> <i class="fa fa-calendar"></i> </span>
			</div>
		</div>
	</div>
</div>
<div class="row">
	<div class="col-md-6">
		<%= f.input :balance_amount, label: '余款预收金额' %>
	</div>
	<div class="col-md-6">

		<div class="form-group date optional form-group-valid">
			<label class="form-control-label optional" for="balance_date">余款预收日期</label>
			<div class="input-group">
				<input name="invoice[balance_date]" class="form-control date-picker" id="invoice_balance_date" type="text" data-date-format="yyyy-mm-dd">
				<span class="input-group-addon"> <i class="fa fa-calendar"></i> </span>
			</div>
		</div>
	</div>
</div>

<div class="row">
	<div class="col-md-12">
		<div class="form-title">
			开票订单
		</div>

	</div>
</div>

<div class="row">
	<div class="col-md-12">

		<% if @orders.presence %>

		<table class="table table-bordered table-hover" id="invoice_order">
			<thead>
				<tr>

					<th>日期</th>
					<th>订单编号</th>
					<th>客户</th>
					<th>客户订单号</th>
					<th>客户订单日期</th>
					<th>金额</th>
					<th>联通合同号</th>
					<th>铁塔财务报账号</th>
					<th></th>
				</tr>
			</thead>

			<tbody>
				<% i =0 %>
				<% @orders.each do |order| %>

				<tr>
					<td><%= order.created_at.strftime("%Y-%m-%d") %>
					<input type="number" id="invoice_orders_invoices_attributes_<%=i%>_order_id" name="invoice[orders_invoices_attributes][<%= i%>][order_id]" value=<%= order.id%> class="hidden">
					</td>
					<td><%= order.order_code %></td>
					<td><%= order.customer.name %></td>
					<td><%= order.customer_po %></td>
					<td><%= order.order_date %></td>
					<td><%= order.amount %></td>
					<td><%= order.contract_no %></td>
					<td><%= order.tieta_settlement_no %></td>
					<td><%= link_to image_tag('trash.gif'), '#',id: "invoice_order_"+i.to_s  %></td>
				</tr>
				<% i += 1 %>
				<% end %>
			</tbody>
		</table>

		<% end %>
	</div>
</div>
<hr />
<%= f.button :submit, '提交',class: "btn btn-blue" %>

<% end %>
